$(function () {
    obj.init();

});

var obj = new function () {
    'use strict';
    return {
        dataGrid:null,
        init:function () {
            this.dataGrid = new xhDataGrid($('#list'), 'appserver/getStayShelf');
            this.dataGrid.parseToolbar().init().activeButton([], []);
            this.funObj().bindDataGridEvent();
            if ($('#bt_list_menu').length > 0) {
                this.funObj().initMenu();
            }
            this.listener();
        },
        listener:function () {
            var $this = this;


            $('#bt_list_search').on('click',function () {
                $this.funObj().search();
            });

            xhTool.bindDocKeyDown($('#bt_list_search'));
        },
        funObj:function () {
            var $this = this;
            return {
                bindDataGridEvent:function () {
                    $this.dataGrid.onLoadSuccess = function () {
                        $this.dataGrid.clear();
                    }
                },
                initMenu:function () {
                    var  $btn_menu=$('#bt_list_menu').menubutton({
                        iconCls: 'fa fa-bars',
                        menu: '#mm'
                    });

                    $($btn_menu.menubutton('options').menu).menu({
                        onClick: function (item) {
                            //item 的相关属性参见API中的menu
                            var appIdArr       = $this.dataGrid.getSelectValues('appId');
                            var versionCodeArr = $this.dataGrid.getSelectValues('versionCode');
                            if(!appIdArr){
                                window.top.xhTop.showError('错误' , '请先选择一个应用');
                                return false;
                            }
                            if (item.text == '通过') {
                                xhExtra.askChangeStatus('appserver/agreeStayShelf',{appIdArr:appIdArr,versionCodeArr:versionCodeArr},$this.dataGrid,'确定要上架这个应用版本吗？',function (res) {
                                    window.top.xhTop.showSuccess(res.msg);
                                    $this.dataGrid.reload();
                                })
                            } else if(item.text == '拒绝'){
                                xhExtra.askChangeStatus('appserver/refuseStayShelf',{appIdArr:appIdArr,versionCodeArr:versionCodeArr},$this.dataGrid,'确定要拒绝上架这个应用版本吗？',function (res) {
                                    window.top.xhTop.showSuccess(res.msg);
                                    $this.dataGrid.reload();
                                })
                            }
                        }
                    });
                },
                search:function () {
                    var key = xhExtra.getValue($('#list_search'));
                    $this.dataGrid.reload({key:key});
                }
            }
        }
    }
};